package cn.stylefeng.guns.modular.order.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.order.entity.OrderClientVolDetail;
import cn.stylefeng.guns.modular.order.mapper.OrderClientVolDetailMapper;
import cn.stylefeng.guns.modular.order.model.params.OrderClientVolDetailParam;
import cn.stylefeng.guns.modular.order.model.result.OrderClientVolDetailResult;
import  cn.stylefeng.guns.modular.order.service.OrderClientVolDetailService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 新零帮出库汇总 服务实现类
 * </p>
 *
 * @author zhangzh
 * @since 2024-06-25
 */
@Service
public class OrderClientVolDetailServiceImpl extends ServiceImpl<OrderClientVolDetailMapper, OrderClientVolDetail> implements OrderClientVolDetailService {

    @Override
    public void add(OrderClientVolDetailParam param){
        OrderClientVolDetail entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(OrderClientVolDetailParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void deleteBySpec(OrderClientVolDetailParam param) {
        this.baseMapper.deleteByDateDt(param);
    }

    @Override
    public void update(OrderClientVolDetailParam param){
        OrderClientVolDetail oldEntity = getOldEntity(param);
        OrderClientVolDetail newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public OrderClientVolDetailResult findBySpec(OrderClientVolDetailParam param){
        return null;
    }

    @Override
    public List<OrderClientVolDetailResult> findListBySpec(OrderClientVolDetailParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(OrderClientVolDetailParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(OrderClientVolDetailParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private OrderClientVolDetail getOldEntity(OrderClientVolDetailParam param) {
        return this.getById(getKey(param));
    }

    private OrderClientVolDetail getEntity(OrderClientVolDetailParam param) {
        OrderClientVolDetail entity = new OrderClientVolDetail();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
